package com.weirong.smartvault.dao;

import com.weirong.smartvault.entity.Authority;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Collection;
import java.util.List;

@Repository
@Qualifier("authorityRepository")
public interface AuthorityRepository extends JpaRepository<Authority, Integer> {

    public List<Authority> findByParentId(int parentId);


    @Modifying
    @Transactional
    @Query("update Authority auth set auth.remark = ?1 where auth.id = ?2")
    public int updateRemarkFor(String newRemark, int id);

    public List<Authority> findAllByGrade(Integer grade);

    Authority getByName(String name);

    Authority findByRemark(String remark);

    List<Authority> findAllByIdIn(Collection<Integer> ids);
}
